﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;

namespace InscriberControlClient
{
    /// <summary>
    /// Interaction logic for Window4.xaml
    /// </summary>
    /// 
   /* public class Task
    {
        public string Task { get; set; }
    }*/

    public partial class Window4 : Window
    {
        public Window1 m_parent=null;
        public bool _isDragging = false;

        public Window4(Window1 wd)
        {
            InitializeComponent();
            Functionality.getPlayList(treeView1, treeView2);
            m_parent = wd;
        }

        private void treeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeView tree = (TreeView)sender;
            TreeViewItem temp = ((TreeViewItem)tree.SelectedItem);
            try
            {
                string news_id=temp.Tag.ToString().Split('_')[0];
                string reports_id = temp.Tag.ToString().Split('_')[1];
                m_parent.RenewChildWindows(news_id, reports_id);
                //MessageBox.Show(news_id + "----" + reports_id);
            }
            catch (Exception ex) { }
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {   
            Window wd=((Window)sender);
            if (wd.Visibility.ToString().Equals("Visible")){
            this.Hide();
            e.Cancel = true;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Functionality.getPlayList(treeView1, treeView2);
        }

        private void treeView2_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (!_isDragging && e.LeftButton == MouseButtonState.Pressed)
                {
                    // _isDragging = true;
                    DragDrop.DoDragDrop(treeView2, treeView2.SelectedValue, DragDropEffects.Move);
                }
            }
            catch (Exception ex) { }
        }

        private void treeView2_DragOver(object sender, DragEventArgs e)
        {
          /*  if (e.Data.GetDataPresent(typeof(System.String)))
            {
                e.Effects = DragDropEffects.Move;
            }
            else
            {
                e.Effects = DragDropEffects.None;
            }*/
        }

        private void treeView2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
        }

        private void treeView2_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {

            TreeView tree = (TreeView)sender;
            TreeViewItem temp = ((TreeViewItem)tree.SelectedItem);
            try
            {
                Functionality.si.news_id = temp.Tag.ToString().Split('_')[0];
                Functionality.si.rep_id= temp.Tag.ToString().Split('_')[1];
                Functionality.si.repname = temp.Header.ToString();
            }
            catch (Exception ex) { }
        }
    }
}
